package com.example.xm.controller;

import com.example.xm.entity.DingCai;
import com.example.xm.entity.Fenlei;
import com.example.xm.entity.Video;
import com.example.xm.mapper.DingcaiMapper;
import com.example.xm.mapper.VideoMapper;
import com.example.xm.service.IDingcaiService;
import com.example.xm.service.IFenleiService;
import com.example.xm.web.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dingcai")
public class DingcaiController {
    @Autowired
    VideoMapper videoMapper;
    @Autowired
    IDingcaiService dingcaiService;
    @Autowired
    DingcaiMapper dingcaiMapper;
@GetMapping("/shoucang")
    public Result shoucang(Integer uid,Integer vid) {
    dingcaiService.shoucang(uid,vid);
    return Result.success();
}
    @GetMapping("/add")
    public Result add(DingCai dingCai) {
        if(dingCai.getType()==1){
            videoMapper.updateNum(dingCai.getVid(),"ding",1);
        }else{
            videoMapper.updateNum(dingCai.getVid(),"cai",1);
        }

        dingcaiMapper.add(dingCai);
        return Result.success();
    }
    @GetMapping("/remove")
    public Result remove(DingCai dingCai) {
        if(dingCai.getType()==1){
            videoMapper.updateNum(dingCai.getVid(),"ding",-1);
        }else{
            videoMapper.updateNum(dingCai.getVid(),"cai",-1);
        }
        dingcaiMapper.del(dingCai);
        return Result.success();
    }
    @GetMapping("/list")
    public Result list(DingCai dingCai) {
     List<Video> list= dingcaiMapper.selectList2(dingCai.getUid(),dingCai.getType());
     return Result.success(list);
    }
}
